package com.xhsj.user.sms.transfer.web;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xhsj.user.sms.transfer.entity.TbTaskTransfer;
import com.xhsj.user.sms.transfer.service.TbTaskTransferService;
import com.xhsj.user.utils.Message;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


/**
 * <p>
 * 任务转让 前端控制器
 * </p>
 *
 * @author suxiaolin
 * @since 2020-07-01
 */
@Slf4j
@Api(tags = "任务转让")
@RestController
@RequestMapping("/transfer/tbTaskTransfer")
public class TbTaskTransferController {

	@Autowired
    public TbTaskTransferService service;


	@ApiOperation(value = "任务转让,保存/修改", notes = "任务转让,保存和修改方法")
	@RequestMapping(value = "/save", method = RequestMethod.POST)
    //@PreAuthorize("hasAuthority('tb:task:transfer:edit')")
	public Message save(@RequestBody List<TbTaskTransfer> data){
    	try {
    		service.saveTbTaskTransfer(data);
			return Message.success("成功");
		} catch (Exception e) {
			log.error("保存失败:{}",e);
        	return Message.error(1,"失败");
		}

	}


	@ApiOperation(value = "任务转让删除", notes = "通过id删除任务转让信息。")
	@RequestMapping(value = "/delete", method = RequestMethod.GET)
    //@PreAuthorize("hasAuthority('tb:task:transfer:delete')")
	public Message delete(@RequestParam(value="id") String id) {
		try {
			service.removeById(id);
        	return Message.success("成功");
		} catch (Exception e) {
			log.error("删除失败:{}",e);
            return Message.error(1,"失败");
		}

	}

	@ApiOperation(value = "批量删除", notes = "批量删除。")
	@RequestMapping(value = "/batchDelete", method = RequestMethod.POST)
	public Message batchDelete(@RequestBody List<String> list) {
		try {
			service.removeByIds(list);
    		return Message.success("成功");
		} catch (Exception e) {
    		log.error("删除失败:{}",e);
    		return Message.error(1,"失败");
		}
    }

	@ApiOperation(value = "分页查询任务转让list", notes = "带参数查询,{\"page\": 1,\"size\": 5,......}。支持模糊查询")
	@RequestMapping(value="/findList",method = RequestMethod.POST)
    //@PreAuthorize("hasAuthority('tb:task:transfer:view')")
	public Message findList(@RequestBody Map<String,Object> data) {
        try {
        	IPage<TbTaskTransfer> selectPage = service.selectPage(data);
    		return Message.success("成功",selectPage.getRecords(),selectPage.getTotal(),selectPage.getPages());
        } catch (Exception e) {
			log.error("查询异常:{}",e);
    		return Message.error(1,"失败");
        }
	}

	@ApiOperation(value = "查询任务转让所有数据list", notes = "查询任务转让所有数据list。")
	@RequestMapping(value="/findAll",method = RequestMethod.POST)
    //@PreAuthorize("hasAuthority('tb:task:transfer:view')")
	public Message findAll(){
        return Message.success("成功",service.selectAll());
	}


	@ApiOperation(value = "通过id获取任务转让实体类", notes = "通过id获取任务转让实体类。")
	@RequestMapping(value="/getById",method = RequestMethod.GET)
    //@PreAuthorize("hasAuthority('tb:task:transfer:view')")
	public Message getById(@RequestParam(value="id") String id) {
    	return Message.success("成功",service.getById(id));
	}

	@ApiOperation(value = "通过id获取实体类详细信息", notes = "通过id获取实体类详细信息。")
	@RequestMapping(value="/detail",method = RequestMethod.GET)
    //@PreAuthorize("hasAuthority('tb:task:transfer:view')")
	public Message detail(@RequestParam(value="id") String id) {
    	return Message.success("成功",service.getById(id));
	}


    @ApiOperation(value = "接收", notes = "接收")
    @RequestMapping(value = "/receiveTask", method = RequestMethod.POST)
    public Message receiveTask(@RequestBody List<TbTaskTransfer> data) {
        try {
         service.receiveTask(data);
         return Message.success("接收成功");
        } catch (Exception e) {
            log.error("删除失败:{}",e);
            return Message.error(1,"失败");
        }

    }

	@ApiOperation(value = "接收海外申请专利", notes = "接收海外申请专利")
    @PostMapping("/receiveOverseasApply")
    public Message receiveOverseasApply(@RequestBody List<Map<String,String>> data) {

		try{
			service.receiveOverseasApply(data);
			return Message.success("接收成功");
		} catch (Exception e) {
			log.error("删除失败:{}",e);
			return Message.error(1,"失败");
		}
	}


	@ApiOperation(value = "拒绝", notes = "拒绝")
	@RequestMapping(value = "/refuseTask", method = RequestMethod.POST)
	public Message refuseTask(@RequestBody List<String> data) {
		try {
			service.refuseTask(data);
			return Message.success("拒绝成功");
		} catch (Exception e) {
			log.error("删除失败:{}",e);
			return Message.error(1,"失败");
		}
	}


	@ApiOperation(value = "撤销", notes = "撤销")
	@RequestMapping(value = "/revokeTask", method = RequestMethod.POST)
	public Message revokeTask(@RequestBody List<String> data) {
		try {
			service.revokeTask(data);
			return Message.success("撤销成功");
		} catch (Exception e) {
			log.error("删除失败:{}",e);
			return Message.error(1,"失败");
		}
	}

}

